package com.ruoyi.generator.service;

import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.generator.entity.*;
import org.apache.commons.lang3.time.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.generator.mapper.ProjectMapper;

import java.text.ParseException;
import java.time.OffsetDateTime;
import java.time.format.DateTimeFormatter;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

/**
 * 业务字段 服务层实现
 * 
 * @author ruoyi
 */
@Service
public class ProjectServiceImpl implements ProjectService
{
	@Autowired
	private ProjectMapper ProjectMapper;


	@Override
	public int insertProject(Project project) throws ParseException {
		project.setCreateTime(new Date());
		project.setUpdateTime(new Date());
		project.setDelFlag("0");
		System.out.println("期望交付日期："+project.getExpectedDeliveryDate());
		String currentUsername = SecurityUtils.getUsername(); // 假设你使用Spring Security
		project.setCreateBy(currentUsername);
		project.setUpdateBy(currentUsername);
		return ProjectMapper.insertProject(project);
	}

	@Override
	public List<Project> selectProjectList(ProjectSearchCriteria projectSearchCriteria) {
		List<Project> projectList=ProjectMapper.selectProjectList(projectSearchCriteria);
		return projectList;
	}


	@Override
	public int deleteProjectById(String id) {
		 return ProjectMapper.deleteProjectById(id);
	}

	@Override
	public List<Object> selectList(QuerySearch querySearch) {
		List<Object> result = new ArrayList<>(); // 使用 List<Object>
		if ("contract".equals(querySearch.getType())) { // 查询合同详情
			List<Contract> contract = ProjectMapper.selectContract(querySearch.getId());
			result.addAll(contract); // 添加 Project 对象
		} else { // 查询客户详情
			List<Customer> customer = ProjectMapper.selectCustomers(querySearch.getId());
			result.addAll(customer); // 添加 Customer 对象
		}

		return result;
	}

	@Override
	public List<Project> selectProjectlist() {
		return null;
	}

}
